<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // ES5中构造函数的继承
    // 父级构造函数
    function Phone(brand, price) {
      this.brand = brand;
      this.price = price;
    }

    Phone.prototype.call = function () {
      console.log("我可以打电话");
    }


    // 子级构造函数
    function SmartPhone(brand, price, color, size) {
      // 改变父构函中的this指向子构函的对象
      Phone.call(this, brand, price);
      this.color = color;
      this.size = size;
    }

    // 设置子级构函的原型对象
    SmartPhone.prototype = new Phone;
    SmartPhone.prototype.constructor = SmartPhone;

    // 声明子类方法
    SmartPhone.prototype.photo = function () {
      console.log("我可以拍照");
    }
    SmartPhone.prototype.playGame = function () {
      console.log("我可以玩游戏");
    }

    // 实例化子级构函
    const chuizi = new SmartPhone('锤子', 2499, '黑色', '5.5inch');
    console.log(chuizi);
    const xiaomi = new Phone('小米', 1999)
    console.log(xiaomi);



    // 理解原型链
    function Nphone(brand, price) {
      this.brand = brand;
      this.price = price;
    }

    Nphone.prototype.call = function () {
      console.log("我可以打电话1");
      console.log(this);
    }

    function Mphone(brand, price) {
      this.brand = brand;
      this.price = price;
    }

    Mphone.prototype.call = function () {
      console.log("我可以打电话2");
    }

    const np = new Nphone('小米1', 1999)
    const mp = new Mphone('小米2', 2999)
    console.log(np);
    console.log(mp);
  </script>
</body>

</html>